<template>
  <div class="import_article">
    <Row justify="start" style="marginbottom: 20px" v-if="unlocking('0207030702')">
      <Col>
        <Button type="primary" @click="exportFun" class="aciton" style="z-index: 9999">导出</Button>
      </Col>
    </Row>
    <dt-grid ref="table" :page="page" :onFetch="onFetch" :select="{ sort: sortCase }" />
    <detail-modal ref="detailModal" />
  </div>
</template>

<script>
  import searchOpt from './opt/search'
  import Column from './opt/column.js'
  import mgr from './biz'
  import detailModal from './component/detailModal'
  export default {
    components: { detailModal },
    data() {
      return {
        pyqVisitCountType: '',
        visitCountType: '',
        org: '',
        page: {
          current: 1
        },
        filterParams: {}
      }
    },
    methods: {
      sortCase(sort) {
        console.log(sort)
        if (sort.prop == '_txt_viewCount') {
          this.visitCountType = sort.order == 'desc' ? 2 : sort.order == 'asc' ? 1 : ''
        } else {
          this.visitCountType = ''
        }
        if (sort.prop == '_txt_pyqViewCount') {
          this.pyqVisitCountType = sort.order == 'desc' ? 2 : sort.order == 'asc' ? 1 : ''
        } else {
          this.pyqVisitCountType = ''
        }
        this.$refs.table.fetch()
      },
      onFetch(data) {
        let params = {
          ...data,
          ...this.org
        }
        this.filterParams = params
        return mgr.list({ ...params }).then((res) => {
          console.log(res)
          return res
        })
      },
      init(org) {
        this.org = org
        this.$refs.table.init(this, new Column(this))

        this.$refs.table.fetch(true)
      },
      delFun(data) {
        this.$Modal.confirm({
          title: '是否下架',
          content: '下架后笔记将从列表中移除，是否确认下架？',
          okText: '下架',
          cancelText: '取消',
          onOk: () => {
            mgr.off(data.id).then((res) => {
              this.$refs.table.fetch()
            })
          }
        })
      },
      viewFun(data) {
        this.$refs.detailModal.show(data.id)
      },
      exportFun() {
        mgr.exportList({ ...this.filterParams })
      }
    },
    mounted() {
      if (this.$tool.getStorage('isbuildFlag') == 'buildpage') {
        this.$refs.table.init(this, new Column(this))
        this.$refs.table.fetch()
      }
    }
  }
</script>
<style lang="scss" scoped>
  .import_article {
    padding: 20px;
  }
</style>
